package kgame5.kgu.ai {
import kgame5.kmath.MathDG;

/**
 * @author kk
 * 隔一个随机的时间触发一次行为
 */
public class RandomTrigger {
	private var maxTick:int,minTick:int;//随机范围
	private var tick:int;
	private var nextTick:int;
	public function RandomTrigger(minTick:int,maxTick:int){
		this.maxTick=maxTick;
		this.minTick=minTick;
		
		next();
	}

	//返回的是此次是否触发
	public function update():Boolean{
		tick++;
		if(tick==nextTick){
			next();
			return true;
		}
		return false;
	}
	
	private function next():void{
		nextTick=MathDG.random(minTick, maxTick);
		tick=0;
	}
}//end of class
}
